package com.codyy.lib.base.application

import android.os.Bundle
import android.util.Log
import android.widget.TextView
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.DividerItemDecoration.VERTICAL
import androidx.recyclerview.widget.RecyclerView
import com.codyy.lib.base.application.repos.adapter.ArticleAdapter
import com.codyy.lib.base.application.repos.model.DataXX
import com.codyy.lib.base.application.repos.viewmodel.ArticleViewModel
import com.codyy.lib_common.base.fragment.BasePagingFragment
import com.codyy.lib_common.base.viewmodel.BaseViewModel
import com.kennyc.view.MultiStateView
import org.koin.android.ext.android.getKoin
import org.koin.androidx.viewmodel.ext.android.viewModel

class ArticleFragment :BasePagingFragment<DataXX, ArticleViewModel,ArticleAdapter.ViewHolder>(){
    private val mArticleViewModel:ArticleViewModel by viewModel()
    override fun afterViewCreated() {
        getView(MultiStateView.ViewState.ERROR)?.findViewById<TextView>(R.id.tv_retry)
            ?.setOnClickListener {
                mArticleViewModel.refresh()
            }
        getView(MultiStateView.ViewState.NONETWORK)?.findViewById<TextView>(R.id.tv_retry)
            ?.setOnClickListener {
                mArticleViewModel.refresh()
            }
    }

    override fun getAdapter(): PagedListAdapter<DataXX, ArticleAdapter.ViewHolder> =ArticleAdapter()

    override fun getViewModel(): BaseViewModel =mArticleViewModel
    override fun addItemDecoration(recyclerView: RecyclerView) {
        recyclerView.addItemDecoration(DividerItemDecoration(AppContext,VERTICAL))
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        Log.e("token", getKoin().getProperty("token")?:"")
    }
}